<template>
  <div>
    <el-card class="top"><el-header>红包记录</el-header></el-card>

    <!-- 表格展示 -->
    <el-card>
      <el-input placeholder="红包名称" prefix-icon="el-icon-search" style="width: 200px" v-model="name">
      </el-input>
      <el-button type="warning" @click="reload" plain>查询</el-button>
      <el-table :data="redList" style="width: 100%" :sort-by.sync="sortKey" :sort-orders="['ascending', 'descending']">
        <el-table-column type="index" label="编号" width="50" align="center">
        </el-table-column>
        <el-table-column prop="uname" label="用户名" width="90" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="用户联系方式" width="120" align="center">
        </el-table-column>
        <el-table-column prop="rname" label="红包名" width="120" align="center">
        </el-table-column>
        <el-table-column prop="money" label="红包金额" width="100" align="center" sortable>
        </el-table-column>
        <el-table-column prop="geytime" label="抢红包时间" width="200" align="center" sortable>
        </el-table-column>
        <el-table-column prop="usetime" label="使用时间时间" width="200" align="center" sortable>
        </el-table-column>
        <el-table-column prop="expiredtime" label="过期时间(天)" width="150" align="center" sortable>
        </el-table-column>
        <el-table-column prop="state" label="状态" width="100" align="center" sortable>
        </el-table-column>
      </el-table>
    </el-card>

    <!--    分页-->
    <el-row>
      <el-col style="text-align:right">
        <el-pagination :current-page="currentPage" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-size="pageSize" :page-sizes="[5, 10, 15]" layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>

</template>

<script>
import { del } from 'vue';

export default {
  data() {
    return {
      rid: null,
      user: {},
      name: "",
      redList: [],
      timevalue: [new Date(), new Date()],
      formLabelWidth: '120px',
      //配置分页
      currentPage: 1,
      pageSize: 5,
      total: 0,
      sortKey: ''
    };

  },

  mounted() {
    this.reload();
    if (localStorage.getItem("user")) {
      this.user = JSON.parse(localStorage.getItem("user"))
      console.log(JSON.stringify(this.user.uid));

    }
  },

  methods: {

    reload() {
      this.$axios.get("/record/findAll?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize + "&name=" + this.name).then((res) => {
        console.log(res.data.data);
        this.redList = res.data.data.list
      });
    },

    handleChange(value) {
      console.log(value);
    },

    //显示查询出的总条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.reload();
    },

    //点击新页查询的数据
    handleCurrentChange(val) {
      this.currentPage = val;
      this.reload();
    },

    changeTime() {
      this.addform.starttime = this.timevalue[0]
      this.addform.endtime = this.timevalue[1]
    }
  },
};
</script>

<style scoped>
.el-header {
  text-align: center;
  line-height: 30px;
  size: 120px;
}

.top {
  background-color: #D3D3D3;
  height: 60px;
}

.el-card {
  margin-top: 10px;
  margin-left: 30px;
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>